<?php
require_once '../DTO/Vung.php';
require_once 'DBConnection.php';

class VungDAO extends DBConnection{
	public function __construct(){
		parent::__construct();
	}
	
	//Lấy danh sách tất cả các vùng
	public function getVung(){
		$sql = "select * from vung";
		
		$res = mysql_query($sql, $this->hDB);
		
		if(!$res){
			die("Failed getting vung");
		}
		
		if(mysql_num_rows($res)){
			$objs = array();
			$temp = mysql_fetch_assoc($res);
			while ($temp){
				$objs[] = new Vung($temp['MaVung'], $temp['TenVung']);
				$temp = mysql_fetch_assoc($res);
			}
			return $objs;
		}else{
			return array();
		}
	}
	
	//insert into vung
	public function insert(Vung $vung){
		$tenVung = $vung->getTenVung();
		
		$sql = "insert into vung (TenVung) values ('$tenVung')";
		
		$res = mysql_query($sql);
		
		if(!$res){
			die("Failed insert into vung");
		}
	}
	
	//delete from vung
	public function delete($maVung){
		$sql = "delete from vung where MaVung='$maVung'";
		
		$res = mysql_query($sql);
		
		if(!$res){
			die("Failed delete from vung");
		}
	}
}








